﻿using SwenAssigment.Classes;
using SwenAssigment.DBClasses;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SwenAssigment
{
    public partial class StaffSearch : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void StaffNameSubmitBtn_Click(object sender, EventArgs e)
        {
            NoDataEnteredLbl.Visible = false;
            NoDataFoundLbl.Visible = false;
            GridView1.Visible = false;
            if (StaffNameTbx.Text.Equals(""))
            {
                NoDataEnteredLbl.Visible = true;
            }
            else
            {
                GridView1.DataSource = StaffDBManager.GetStaffsByName(StaffNameTbx.Text);
                GridView1.DataBind();
                if (GridView1.Rows.Count == 0)
                {
                    NoDataFoundLbl.Visible = true;
                }
                else
                {
                    GridView1.Visible = true;
                }
            }
        }

        protected void JobSubmitBtn_Click(object sender, EventArgs e)
        {
            NoDataEnteredLbl.Visible = false;
            NoDataFoundLbl.Visible = false;
            GridView1.Visible = false;
            if (JobTbx.Text.Equals(""))
            {
                NoDataEnteredLbl.Visible = true;
            }
            else
            {
                GridView1.DataSource = StaffDBManager.GetStaffsByJob(JobTbx.Text);
                GridView1.DataBind();
                if (GridView1.Rows.Count == 0)
                {
                    NoDataFoundLbl.Visible = true;
                }
                else
                {
                    GridView1.Visible = true;
                }
            }
        }

        protected void NricSubmitBtn_Click(object sender, EventArgs e)
        {
            NoDataEnteredLbl.Visible = false;
            NoDataFoundLbl.Visible = false;
            GridView1.Visible = false;
            if (NRICTbx.Text.Equals(""))
            {
                NoDataEnteredLbl.Visible = true;
            }
            else
            {
                var Result = StaffDBManager.GetStaffByNric(NRICTbx.Text);
                if (Result.NRIC == null)
                {
                    NoDataFoundLbl.Visible = true;
                }
                else
                {
                    var Staff = new List<Staff>() { Result };
                    GridView1.DataSource = Staff;
                    GridView1.DataBind();
                    GridView1.Visible = true;
                }
            }
        }
    }
}